package com.example.administrator.printoutindemo.services;

import android.content.Context;
import android.view.Gravity;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Tools {
	/***
	 * 半角转换为全角
	 *
	 * @param input
	 * @return
	 */
	public static String ToDBC(String input) {
		char[] c = input.toCharArray();
		for (int i = 0; i < c.length; i++) {
			if (c[i] == 12288) {
				c[i] = (char) 32;
				continue;
			}
			if (c[i] > 65280 && c[i] < 65375)
				c[i] = (char) (c[i] - 65248);
		}
		return new String(c);
	}

	/**
	 * * 去除特殊字符或将所有中文标号替换为英文标号
	 *
	 * @param str
	 * @return
	 */
	public static String stringFilter(String str) {
		str = str.replaceAll("【", "[").replaceAll("】", "]")
				.replaceAll("！", "!").replaceAll("：", ":");// 替换中文标号
		String regEx = "[『』]"; // 清除掉特殊字符
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.replaceAll("").trim();
	}

	// 显示提示
	public static void showDialogInfo(Context context, TextView btn, String msg) {
		int[] location = new int[2];
		btn.getLocationOnScreen(location);
		Toast toast = Toast.makeText(context, msg, Toast.LENGTH_LONG);

		toast.setGravity(Gravity.LEFT | Gravity.TOP, location[0], location[1]);
		toast.show();
	}

	// 显示提示
	public static void showDialogInfo(Context context, String msg) {

		Toast toast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
		toast.show();
	}

//	public GeoPoint gpsToBaidu(String data) {// data格式 nmea标准数据
//											// ddmm.mmmmm,ddmm.mmmm
//											// 如3030.90909,11449.1234
//
//		String[] p = data.split(",");
//
//		int lat = (int) (((int) (Float.valueOf(p[0]) / 100) + (100 * (Float// 将ddmm.mmmm格式转成dd.ddddd
//
//				.valueOf(p[0]) / 100.0 - (int) (Float.valueOf(p[0]) / 100)) / 60.0)) * 1E6);
//
//		int lon = (int) (((int) (Float.valueOf(p[1]) / 100) + (100 * (Float
//
//		.valueOf(p[1]) / 100.0 - (int) (Float.valueOf(p[1]) / 100)) / 60.0)) * 1E6);
//
//		GeoPoint pt = new GeoPoint(lat, lon);
//
//		return CoordinateConvert.fromWgs84ToBaidu(pt);// 转成百度坐标
//
//	}


}